#include "cdelegate.h"
#include "clistview.h"
#include "mainwindow.h"

#include <QHBoxLayout>
#include <QStandardItemModel>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    ///model数据构造和添加
    QStringList list;
    list<<"animal"<<"spring"<<"tiger"<<"lion"<<"elephone"<<"stardog"<<"greengrass";
    QStandardItemModel* model = new QStandardItemModel(this);
    for (int i = 0; i < list.size(); ++i)
    {
        QStandardItem* item = new QStandardItem;
        item->setFlags(item->flags() | Qt::ItemIsDragEnabled);
        item->setData(QVariant::fromValue(list.at(i)), Qt::UserRole);
        model->appendRow(item);
    }

    //ListView初始化
    CListView *listView = new CListView(this);
    listView->setModel(model);

    //委托初始化并添加到ListView
    CDelegate *delegate = new CDelegate(this);
    listView->setItemDelegate(delegate);

    //将 ListView添加到布局
    this->setCentralWidget(listView);
}

MainWindow::~MainWindow()
{

}
